<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<body>
<script type="text/javascript">
	$(function() {
		djt_SD_editIndex = undefined;
		
		var Sobid=<%=request.getAttribute("salaryId")%>;
		//console.log("Sobid"+Sobid);
		var maxLength=<%=request.getAttribute("maxLength")%>;
		
		$('#djt_SD_dg'+Sobid+'').datagrid({
			fit:true,
	 	   	fitColumns:false,
	 	   	//隔行变色
	 	   	striped:true,
	  	  	nowrap:true,
			toolbar:'#SDtb'+Sobid+'',
			//pagination:true,
			//pageSize:5,
			//pageList:[5,10,20,40],
			border:false,
			//sortName:'salaryId',
			//sortOrder:'asc',
		});

		var s = "";
		s = "[[";
		s = s + "{field:'',title:'',checkbox:true},{field:'0',title:'员工编号',width:'100'},{field:'1',title:'员工姓名',width:'100'},";
		var j = 2;
		for (var i=0;i < maxLength;i++){
			s = s + "{field:'"+j+"',title:'项目名称',width:'100'},"
			j++;
			s = s + "{field:'"+j+"',title:'项目值',width:'100'},"
			j++;
		}
		s = s + "]]";
		options={};
		options.url = '../salaryDetail/queryById?Sid='+Sobid+'';
		options.columns = eval(s);
		$('#djt_SD_dg'+Sobid+'').datagrid(options);
		$('#djt_SD_dg'+Sobid+'').datagrid('reload');
		
	});

	//删除
	function removeS(){
		var Sobid=<%=request.getAttribute("salaryId")%>;
		var rows = $('#djt_SD_dg'+Sobid+'').datagrid('getSelections');
		if(rows.length > 0){
			$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
				if(r){
					var ids = [];
					for(var i = 0; i < rows.length; i++){
						ids.push(rows[i].salaryId)
					}
					var djt_SD_rowData = JSON.stringify(ids);
					$.post('../salaryService/deleteS',{djt_SD_rowData},function(e){
						var info = JSON.parse(e);
						if(info.success){
							$('#djt_SD_dg'+Sobid+'').datagrid('load');
							$('#djt_SD_dg'+Sobid+'').datagrid('unselectAll');
							$.messager.show({
								title:'成功',
								msg:info.msg,
							});
						}else{
							$('#djt_SD_dg'+Sobid+'').datagrid('rejectChanges');
							$.messager.alert('错误',info.msg,'error');
						}
					})
					djt_SD_editIndex = undefined;
				}
			})
		}else{
			$.messager.alert('提示','请选择要删除的记录！','error');
		}
	}

</script>

<div class="easyui-layout" fit="true" border="false">
	<div region="center" border="false">
		<table id="djt_SD_dg${salaryId}"></table>
	
		<div id="SDtb${salaryId}">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeSD()">删除</a>
		</div>
	</div>	
</div>
</body>
